package monopoly;


import java.io.IOException;


public class computer {
	public static void turn() throws IOException{
		if (vars.computer_jail != 0) {
			System.out.println("Computer pays $50 and leaves jail");
			vars.computer_jail = 0;
			vars.computer_money = vars.computer_money - 50;
		}
		vars.dice = dice.dice_roll(vars.dice);
		vars.dice2 = dice.dice_roll(vars.dice);
		if (vars.dice == vars.dice2) {
			System.out.println("The computer rolled doubles.");
			vars.computer_doubles++;
			if (vars.computer_doubles == 3) {
				System.out
						.println("The Computer rolled doubles three times and goes to jail");
				vars.computer_position = 10;
				vars.computer_jail = 1;
			}
		} else {
			vars.computer_doubles = 0;
			vars.var = vars.dice + vars.dice2;
			System.out.println("Computer rolls the dice. It rolls a "+ vars.var);
			vars.computer_position = vars.computer_position+ vars.dice;
		}
		System.in.read();
		// if player passes go, add $200 and subtract 40
		if (vars.computer_position >= 40) {
			System.out.println("Computer passes go and collects $200");
			vars.computer_position = vars.computer_money + 200;
			vars.computer_position = vars.computer_position - 40;
		}
		
		// if lands on a property give option to buy property
		if (arrays.property_type[vars.computer_position] == 0) {
			buy_property();
		} else {
			// if property is owned by you, do nothing
			if (arrays.property_type[vars.computer_position] == 2) {
				System.out.println("Computer lands on and alreadly owns "+ arrays.property_name[vars.computer_position]);
			}
		}
		if (arrays.property_type[vars.computer_position] == 1) {
			
		}
		if (arrays.property_type[vars.computer_position] == 3) {
			System.out.println("Computer lands on Chance");
			chance.computer();
		}
		if (arrays.property_type[vars.computer_position] == 4) {
			System.out.println("Computer lands on community chest");
			community_chest.computer();
		}
		if (arrays.property_type[vars.computer_position] == 5) {
			System.out
					.println("Computer lands on Go and collects $400");
			vars.computer_money = vars.computer_money + 400;
		}
		if (arrays.property_type[vars.computer_position] == 6) {
			System.out
					.println("Computer lands on Income Tax and pays $200");
			vars.computer_money = vars.computer_money - 200;
		}
		if (arrays.property_type[vars.computer_position] == 7) {
			System.out
					.println("Computer lands on luxury tax and pays $100");
			vars.computer_money = vars.computer_money - 100;
		}
		if (arrays.property_type[vars.computer_position] == 8) {
			System.out.println("Computer visits jail");
		}
		if (arrays.property_type[vars.computer_position] == 9) {
			System.out.println("Computer lands on Free Parking.");
		}
		if (arrays.property_type[vars.computer_position] == 10) {
			System.out
					.println("Computer lands on Go To Jail. Computer is now in Jail.");
			vars.computer_position = 10;
		}
		if (vars.computer_doubles == 0) {
			System.out.println("The turn ends");
			vars.turn = 0;
		} else {
			System.out
					.println("Computer rolled doubles and takes another turn.");
		}
		if (vars.computer_money < 0) {
			vars.finished = 2;
		}
		System.out.println("The computer now has $"
				+ vars.computer_money);
		System.in.read();
	}
	public static void buy_property(){
		System.out.println("Computer lands on "
				+ arrays.property_name[vars.computer_position]
				+ ".");
		if (vars.computer_money
				- arrays.property_price[vars.computer_position] > 100) {
			System.out
					.println("Computer buys "
							+ arrays.property_name[vars.computer_position]);
			vars.computer_money = vars.computer_money
					- arrays.property_price[vars.computer_position];
			arrays.property_type[vars.computer_position] = 2;
		} else {
			System.out
					.println("Computer does not buy "
							+ arrays.property_name[vars.computer_position]);
		}
	}
	public static void pay_rent(){
		if (vars.computer_position == 5
				|| vars.computer_position == 15
				|| vars.computer_position == 25
				|| vars.computer_position == 35) {
			vars.var = 0;
			if (arrays.property_type[5] == 1) {
				vars.var++;
			}
			if (arrays.property_type[15] == 1) {
				vars.var++;
			}
			if (arrays.property_type[25] == 1) {
				vars.var++;
			}
			if (arrays.property_type[35] == 1) {
				vars.var++;
			}
			if (vars.var == 1) {
				vars.var = 25;
			}
			if (vars.var == 2) {
				vars.var = 50;
			}
			if (vars.var == 3) {
				vars.var = 100;
			}
			if (vars.var == 4) {
				vars.var = 200;
			}
			System.out
					.println("Computer lands on"
							+ arrays.property_name[vars.computer_position]
							+ " and is charged $" + vars.var
							+ ".");
			vars.computer_money = vars.computer_money
					- vars.var;
		} else if (vars.computer_position == 12) {
			if (arrays.property_type[28] == 1) {
				System.out
						.println("Computer lands on The Electric Company and is charged $"
								+ 10 * vars.var + " rent");
				vars.computer_money = vars.computer_money - 10
						* vars.var;
			} else {
				System.out
						.println("computer lands on The Electric Company and is charged $"
								+ 4 * vars.var + " rent");
				vars.computer_money = vars.computer_money - 4
						* vars.var;
			}
		} else if (vars.computer_position == 28) {
			if (arrays.property_type[12] == 1) {
				System.out
						.println("Computer lands on The Water Works and is charged $"
								+ 10 * vars.var + " rent");
				vars.computer_money = vars.computer_money - 10
						* vars.var;
			} else {
				System.out
						.println("Computer lands on The Water Works and is charged $"
								+ 4 * vars.var + " rent");
				vars.computer_money = vars.computer_money - 4
						* vars.var;
			}
		} else {
			System.out
					.println("Computer lands on "
							+ arrays.property_name[vars.computer_position]
							+ ". Player already owns this property. You are charged $"
							+ arrays.property_rent[vars.player_position]
							+ " rent");
			vars.computer_money = vars.computer_money
					- arrays.property_rent[vars.computer_position];
		}
	}
}
